package xyz.xtt.admin.utils;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Optional;

@RefreshScope
@Component
public class PageUtilV2 {

    @Value("${config.defaultCurrent:1}")
    private Integer defaultCurrent;
    @Value("${config.defaultPage_size:20}")
    private Integer defaultPageSize;

    public  Integer getCurrent(Integer current) {
        return  Optional.ofNullable(current).filter(x ->x>=1).orElse(defaultCurrent);
    }

    public  Integer getPageSize(Integer pageSize) {
        return  Optional.ofNullable(pageSize).filter(x ->x>=1).orElse(defaultPageSize);
    }

    @Bean
    public PageUtilV2 pageUtil() {
        return new PageUtilV2();
    }
}
